package com.stefanini.pe.bbva.mbl.in.dao;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.List;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.stefanini.pe.bbva.mbl.carga.in.to.ControlEliminar;
import com.stefanini.pe.bbva.mbl.in.dao.iface.ControlEliminarDAO;
import com.stefanini.pe.bbva.mbl.in.utils.Util;

import org.apache.log4j.Logger;

public class ControlEliminarDAOImpl extends SqlMapClientDaoSupport implements ControlEliminarDAO {
	private static final Logger logger = Logger.getLogger(ControlEliminarDAOImpl.class);

	public ControlEliminarDAOImpl() {
        super();
    }

    public void deleteByPrimaryKey(BigDecimal idControlEliminar){
    	logger.info("Inicio");
    	
    	try{
    	try {
    		ControlEliminar key = new ControlEliminar();
    		key.setIdControlEliminar(idControlEliminar);
    		getSqlMapClientTemplate().getSqlMapClient().startTransaction();
    		getSqlMapClientTemplate().delete("CONTROLELIMINAR.ibatorgenerated_deleteDetalle", key);
    		getSqlMapClientTemplate().delete("CONTROLELIMINAR.ibatorgenerated_deleteByPrimaryKey",key);
    		getSqlMapClientTemplate().getSqlMapClient().commitTransaction();    		
    	}catch(Exception e){
    		logger.error(e.getMessage(), e);
    	}finally{
    		getSqlMapClientTemplate().getSqlMapClient().endTransaction();
    	}
    	}catch(Exception e){
    		logger.error(e.getMessage(), e);
    	}        
    	
    	logger.info("Fin");
    }

    public void insert(ControlEliminar record) {
    	logger.info("Inicio");
    	
        getSqlMapClientTemplate().insert("CONTROLELIMINAR.ibatorgenerated_insert", record);
        
        logger.info("Fin");
    }

    public void insertSelective(ControlEliminar record) {
    	logger.info("Inicio");
    	
        getSqlMapClientTemplate().insert("CONTROLELIMINAR.ibatorgenerated_insertSelective", record);
        
        logger.info("Fin");
    }

    public ControlEliminar selectByPrimaryKey(BigDecimal id_control_eliminar) {
        ControlEliminar key = new ControlEliminar();
        ControlEliminar controlEliminar = null;
        
        logger.info("Inicio");
        
        key.setIdControlEliminar(id_control_eliminar);
        controlEliminar = (ControlEliminar) getSqlMapClientTemplate().queryForObject("CONTROLELIMINAR.ibatorgenerated_selectByPrimaryKey", key);
        
        logger.info("Fin");
        
        return controlEliminar;
    }

    public List selectByCriteria(ControlEliminar controlEliminar) {
        List lista= null;
        
        logger.info("Inicio");
        
        lista= (List)getSqlMapClientTemplate().queryForObject("CONTROLELIMINAR.ibatorgenerated_selectByCriteria", controlEliminar);
        
        logger.info("Fin");
        
        return lista;
    }

    public void updateByPrimaryKeySelective(ControlEliminar record) {
    	logger.info("Inicio");
    	
        getSqlMapClientTemplate().update("CONTROLELIMINAR.ibatorgenerated_updateByPrimaryKeySelective", record);
        
        logger.info("Fin");
    }

    public void updateByPrimaryKey(ControlEliminar record) {
    	logger.info("Inicio");
    	
        getSqlMapClientTemplate().update("CONTROLELIMINAR.ibatorgenerated_updateByPrimaryKey", record);
        
        logger.info("Fin");
    }
    
    public List selectAll(){
        List records = null;
        
        logger.info("Inicio");
        
        records =this.getSqlMapClientTemplate().queryForList("CONTROLELIMINAR.ibatorgenerated_selectAll", null);
     
        logger.info("Fin");
        
        return records;
    }
}